package com.synjones.handsetS8.ild.popup;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.synjones.handsetS8.R;;

/**
 * @author Chris Chan
 * Create on: 2021/7/23}17:04
 * For: 更换手环的弹窗
 * Explain:
 */
public class ChangeBraceletWindow extends PopupWindow {
    private Activity context;
    private View contentView;
    private TextView tvOk;
    private TextView tvCancel;
    private TextView tvBraceletNo;

    private String workerId;

    private OnPopupWindowClickListener onPopupWindowClickListener;

    public ChangeBraceletWindow(Activity context) {
        this(context, null, null);
    }

    public ChangeBraceletWindow(Activity context, View contentView) {
        this(context, contentView, null);
    }

    public ChangeBraceletWindow(Activity context, OnPopupWindowClickListener onPopupWindowClickListener) {
        this(context, context.getLayoutInflater().inflate(R.layout.pop_worker_change_bracelet, null), onPopupWindowClickListener);
    }

    public ChangeBraceletWindow(View contentView, int width, int height) {
        super(contentView, width, height);
        init();
    }

    public ChangeBraceletWindow(Activity context, View contentView, int width, int height) {
        super(contentView, width, height);
        this.context = context;
        init();
    }

    public ChangeBraceletWindow(Activity context, View contentView, OnPopupWindowClickListener onPopupWindowClickListener) {
        super(context);
        this.context = context;
        this.contentView = contentView;

        this.onPopupWindowClickListener = onPopupWindowClickListener;

        setContentView(contentView);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setOutsideTouchable(true);

        init();
    }

    private void init() {
        tvOk = contentView.findViewById(R.id.btn_ok);
        tvCancel = contentView.findViewById(R.id.btn_cancel);
        TextView tvBraceletNo = contentView.findViewById(R.id.tv_bracelet_no);

        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        setOnPopupWindowClickListener(onPopupWindowClickListener);
    }

    @Override
    public void setContentView(View contentView) {
        this.contentView = contentView;
    }

    public void setOnPopupWindowClickListener(OnPopupWindowClickListener onPopupWindowClickListener) {
        this.onPopupWindowClickListener = onPopupWindowClickListener;
        if (null != this.onPopupWindowClickListener) {
            tvOk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "狄安娜", Toast.LENGTH_SHORT).show();
                    onPopupWindowClickListener.onClick(v, null);
                }
            });
        }
    }
}
